REPeat

Syntax: REPeat identifier
    or: REPeat [identifier]  (SMS only)
Location: QL ROM

The SuperBASIC REPeat loop is extremely flexible and provides an alternative to the classic FOR loop. It sets up a perpetual loop which can only be ended (correctly) by means of the EXIT command. The syntax of this SuperBASIC structure can take two forms:

REPeat identifier :statement {:statement}
or
REPeat identifier
{statements}
...
[EXIT identifier]
[NEXT identifier]
...
END REPeat identifier

The first of these variants is known as an in-line REPeat loop. Provided that there is at least one statement following  REPeat, this line will be repeated forever (unless there is an EXIT statement - see below). There is no need for a related  END REPeat statement and therefore the shortest (practicable) in-line REPeat loop possible is:

REPeat loop: IF INKEY$=' ' THEN EXIT loop

If an in-line loop is terminated with EXIT, control will be passed to the statement following the corresponding END REPeat statement (if one exists), or the next program line.  This allows the following:

REPeat loop: IF INKEY$=' ':EXIT loop: END REPeat loop: PRINT 'Phew!'

EXIT is used (in both REPeat loops and FOR loops) to terminate the loop, and the next statement which will be processed is the first statement after the corresponding END REPeat (if one exists). NEXT forces the program to make another pass of the loop, returning program control to the statement following REPeat.

MINERVA NOTES:
This allows string REPeat loops and integer REPeat loops, although the use of the former is dubious. You can of course still use the identifiers within the loop as variables. Integer REPeat loops do not seem to be any quicker than floating point loops.

If you do use a string identifier, Minerva restricts such strings to a maximum of four characters.

String and integer REPeat loops will not safely work on other ROMs (except under SMS), even if they will let you type them in!

SMS NOTES:
Like Minerva, SMS allows string REPeat loops and integer REPeat loops. However, SMS does not restrict the length of a string loop identifier (except to the normal string length limit of 32767 characters).

SMS also allows you to omit the loop identifier, in which case the relative EXIT, NEXT and END REPeat statements must also omit the loop identifier.  This flexibility brings this command more in line with other implementations of BASIC.

Error trapping of incorrectly structured REPeat loops is also improved - please refer to NEXT and END REPeat.

CROSS-REFERENCE:
FOR...END FOR is the other loop type.
